

//************* For getting Longitude and latitude of current place of user ************

var latuser = null;
var longuser = null;

function showLocation(position) 
{
	latuser = position.coords.latitude;
	longuser = position.coords.longitude;
	//alert("Latitude : " + latuser + " Longitude: " + longuser);
	comparePosition();
}

function errorHandler(err) 
{
    if(err.code == 1) 
	{
		alert("Error: Access is denied!");
	}
	else if ( err.code == 2) 
	{
		alert("Error: Position is unavailable!");
	}
}
function getLocation()
{

    if(navigator.geolocation)
	{
      // timeout at 60000 milliseconds (60 seconds)
      var options = {timeout:60000};
      navigator.geolocation.getCurrentPosition(showLocation, errorHandler, options);
    }
	else
	{
		alert("Sorry, browser does not support geolocation!");
	}
}


//************* For comparing Longitude and latitude of user to the other cities ************

function comparePosition()
{
	//alert("Latitude : " + latuser + " Longitude: " + longuser);
	var distFrmMumbai = getDistanceFromLatLonInKm(18.9647,72.8258);
	var distFrmPune = getDistanceFromLatLonInKm(18.5236,73.8478);
	var distFrmNagpur = getDistanceFromLatLonInKm(21.1438,79.0926);
	var distFrmBengalore = getDistanceFromLatLonInKm(12.9833,77.5833);
	var distFrmBelgaum = getDistanceFromLatLonInKm(15.8700,74.5000);
	var distFrmGulbarga = getDistanceFromLatLonInKm(17.3300,76.8300);
	
	//alert(distFrmGulbarga);
	if ( distFrmMumbai<distFrmPune && distFrmMumbai<distFrmNagpur && distFrmMumbai<distFrmBengalore && distFrmMumbai<distFrmBelgaum && distFrmMumbai<distFrmGulbarga )
	{
		//window.locationhref = "mumbai.html";
		window.location = "mumbai.html";
	}
	else if ( distFrmPune<distFrmMumbai && distFrmPune<distFrmNagpur && distFrmPune<distFrmBengalore && distFrmPune<distFrmBelgaum && distFrmPune<distFrmGulbarga )
	{
		//window.locationhref = "mumbai.html";
		window.location = "pune.html";
	}
	else if ( distFrmNagpur<distFrmMumbai && distFrmNagpur<distFrmPune && distFrmNagpur<distFrmBengalore && distFrmNagpur<distFrmBelgaum && distFrmNagpur<distFrmGulbarga )
	{
		//window.locationhref = "mumbai.html";
		window.location = "nagpur.html";
	}
	else if ( distFrmBengalore<distFrmMumbai && distFrmBengalore<distFrmPune && distFrmBengalore<distFrmNagpur  && distFrmBengalore<distFrmBelgaum && distFrmBengalore<distFrmGulbarga )
	{
		//window.locationhref = "mumbai.html";
		window.location = "bengalore.html";
	}
	else if ( distFrmBelgaum<distFrmMumbai && distFrmBelgaum<distFrmPune && distFrmBelgaum<distFrmNagpur  && distFrmBelgaum<distFrmBengalore && distFrmBelgaum<distFrmGulbarga )
	{
		//window.locationhref = "mumbai.html";
		window.location = "belgaum.html";
	}
	else  if ( distFrmGulbarga<distFrmMumbai && distFrmGulbarga<distFrmPune && distFrmGulbarga<distFrmNagpur  && distFrmGulbarga<distFrmBengalore && distFrmGulbarga<distFrmBelgaum )
	{
		//window.locationhref = "mumbai.html";
		window.location = "gulbarga.html";
	}
	else
	{
		//window.locationhref = "mumbai.html";
		window.location = "mumbai.html";
	}
}

function getDistanceFromLatLonInKm(lat1,lon1) 
{
	var R = 6371; // Radius of the earth in km
	var dLat = deg2rad(latuser-lat1);  // deg2rad below
	var dLon = deg2rad(longuser-lon1); 
	var a = 
		Math.sin(dLat/2) * Math.sin(dLat/2) +
		Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(latuser)) * 
		Math.sin(dLon/2) * Math.sin(dLon/2); 
	var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); 
	var d = R * c; // Distance in km
	return d;
}

function deg2rad(deg) 
{
	return deg * (Math.PI/180)
}


//******************* For Sports ******************
function displaySportsMumbai()
{
	document.getElementById('ConcertsMumbai').style.display = "none";
	document.getElementById('SportsMumbai').style.display = "block";
	document.getElementById('upcomingMumbaiConcerts').style.display = "none";
	document.getElementById('browseMumbaiConcerts').style.display = "none";
	document.getElementById('TheatreMumbai').style.display = "none";
	document.getElementById('upcomingMumbaiTheatre').style.display = "none";
	document.getElementById('browseMumbaiTheatre').style.display = "none";
}
function displayUpcomingMumbaiSports()
{
	document.getElementById('upcomingMumbaiSports').style.display = "block";
	document.getElementById('browseMumbaiSports').style.display = "none";
}
function displayBrowseMumbaiSports()
{
	document.getElementById('browseMumbaiSports').style.display = "block";
	document.getElementById('upcomingMumbaiSports').style.display = "none";
}

function browseSportsLists()
{

	if(document.getElementById("select-choice-game").selectedIndex == 1)
	{
		document.getElementById("mumbaibrowselistHockey").style.display = "none";
		document.getElementById("mumbaibrowselistWrestling").style.display = "none";
		document.getElementById("mumbaibrowselistCricket").style.display = "block";
	} 
	else if(document.getElementById("select-choice-game").selectedIndex == 2)
	{
		document.getElementById("mumbaibrowselistFootball").style.display = "block";
	} 
	else if(document.getElementById("select-choice-game").selectedIndex == 3)
	{
		document.getElementById("mumbaibrowselistCricket").style.display = "none";
		document.getElementById("mumbaibrowselistWrestling").style.display = "none";
		document.getElementById("mumbaibrowselistHockey").style.display = "block";
	} 
	else if(document.getElementById("select-choice-game").selectedIndex == 4)
	{
		document.getElementById("mumbaibrowselistRugby").style.display = "block";
	} 
	else if(document.getElementById("select-choice-game").selectedIndex == 5)
	{
		document.getElementById("mumbaibrowselistBodybuilding").style.display = "block";
	}
	else if(document.getElementById("select-choice-game").selectedIndex == 6)
	{
		document.getElementById("mumbaibrowselistCricket").style.display = "none";
		document.getElementById("mumbaibrowselistHockey").style.display = "none";
		document.getElementById("mumbaibrowselistWrestling").style.display = "block";
	}
}




//******************** For Concerts ************************
function displayConcertsMumbai()
{
	document.getElementById('ConcertsMumbai').style.display = "block";
	document.getElementById('upcomingMumbaiConcerts').style.display = "block";
	document.getElementById('SportsMumbai').style.display = "none";
	document.getElementById('upcomingMumbaiSports').style.display = "none";
	document.getElementById('browseMumbaiSports').style.display = "none";
	document.getElementById('TheatreMumbai').style.display = "none";
	document.getElementById('upcomingMumbaiTheatre').style.display = "none";
	document.getElementById('browseMumbaiTheatre').style.display = "none";
}
function displayUpcomingMumbaiConcerts()
{
	document.getElementById('upcomingMumbaiConcerts').style.display = "block";
	document.getElementById('browseMumbaiConcerts').style.display = "none";
}
function displayBrowseMumbaiConcerts()
{
	document.getElementById('browseMumbaiConcerts').style.display = "block";
	document.getElementById('upcomingMumbaiConcerts').style.display = "none";
}
function browseConcertsLists()
{

	if(document.getElementById("select-choice-concert").selectedIndex == 1)
	{
		document.getElementById("mumbaibrowselistdancing").style.display = "none";
		document.getElementById("mumbaibrowselistsinging").style.display = "block";
	} 
	else if(document.getElementById("select-choice-concert").selectedIndex == 2)
	{		
		document.getElementById("mumbaibrowselistsinging").style.display = "none";
		document.getElementById("mumbaibrowselistdancing").style.display = "block";
	} 
	else if(document.getElementById("select-choice-concert").selectedIndex == 3)
	{
		document.getElementById("mumbaibrowselistrock").style.display = "block";
	} 
}





//******************** For Concerts ************************
function displayTheatreMumbai()
{
	document.getElementById('SportsMumbai').style.display = "none";
	document.getElementById('upcomingMumbaiSports').style.display = "none";
	document.getElementById('browseMumbaiSports').style.display = "none";
	document.getElementById('ConcertsMumbai').style.display = "none";
	document.getElementById('upcomingMumbaiConcerts').style.display = "none";
	document.getElementById('browseMumbaiConcerts').style.display = "none";
	document.getElementById('TheatreMumbai').style.display = "block";
	document.getElementById('upcomingMumbaiTheatre').style.display = "block";
}
function displayUpcomingMumbaiTheatre()
{
	document.getElementById('upcomingMumbaiTheatre').style.display = "block";
	document.getElementById('browseMumbaiTheatre').style.display = "none";
}
function displayBrowseMumbaiTheatre()
{
	document.getElementById('browseMumbaiTheatre').style.display = "block";
	document.getElementById('upcomingMumbaiTheatre').style.display = "none";
}


//******************* For Back button *********************
function backButton()
{
	history.go(-1);
}




//******************* Local Database Used ************
	

//need to assign value to these variables from the server
localStorage.section = 'Balcony';
localStorage.row = 'H';
localStorage.zone = '';
localStorage.seats = '10, 11, 12';

function assignCity(city)
{
	if (window.localStorage) 
	{
		//alert(localStorage.cityname);
		localStorage.cityname = city;
	}
	else 
	{
		alert("Your Browser does not support LocalStorage.");
	}
}

function getCity()
{
	if (window.localStorage) 
	{
		document.getElementById('cityName').innerHTML = localStorage.cityname;
	}
	else 
	{
		alert("Your Browser does not support LocalStorage.");
	}
}

function assignData(avail_seats, price, title, venue, time)
{
	if (window.localStorage) 
	{
		localStorage.avail_seats = avail_seats;
		localStorage.price = price;
		localStorage.title = title;
		localStorage.venue = venue;
		localStorage.time = time;
		//alert(localStorage.avail_seats+'...'+localStorage.price+'...'+localStorage.title+'...'+localStorage.venue+'...'+localStorage.time);
	}
	else 
	{
		alert("Your Browser does not support LocalStorage.");
	}
}
function getData()
{
	if (window.localStorage) 
	{
		document.getElementById('Title').innerHTML = localStorage.title;
		document.getElementById('Venue').innerHTML = localStorage.venue;
		document.getElementById('Time').innerHTML = localStorage.time;
		document.getElementById('Section').innerHTML = localStorage.section;
		document.getElementById('Row').innerHTML = localStorage.row;
		document.getElementById('Seats').innerHTML = localStorage.seats;
		document.getElementById('Price').innerHTML = localStorage.price;
		document.getElementById('Avail_seats').innerHTML = localStorage.avail_seats;
		document.getElementById('Zone').innerHTML = localStorage.zone;
		
	}
	else 
	{
		alert("Your Browser does not support LocalStorage.");
	}
}

function assignQuantity()
{
	if (window.localStorage) 
	{
		var qua = document.getElementById("Quantity");
		localStorage.quantity = document.getElementById("Quantity").value;
		//alert(localStorage.quantity);
	}
	else 
	{
		alert("Your Browser does not support LocalStorage.");
	}
}



//********************** Share, Location and Map ****************

function onShare()
{	
	document.getElementById('Content').style.display = "none";
	document.getElementById('Map').style.visibility = "hidden";
	document.getElementById('Share').style.display = "block";
	document.getElementById('Location').style.display = "none";
}
function onMap()
{
	document.getElementById('Content').style.display = "none";
	document.getElementById('Share').style.display = "none";
	document.getElementById('Map').style.visibility = "visible";
	document.getElementById('Location').style.display = "none";
}
function onLocation()
{
	document.getElementById('Location').style.display = "block";
	document.getElementById('Content').style.display = "none";
	document.getElementById('Share').style.display = "none";
	document.getElementById('Map').style.visibility = "hidden";
}

var myCenter=new google.maps.LatLng(18.5236,73.8478);
var marker;

function initialize()
{
	var mapProp = {
	center:myCenter,
	zoom:15,
	mapTypeId:google.maps.MapTypeId.ROADMAP
	};

	var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);

	marker=new google.maps.Marker({
	position:myCenter,
	animation:google.maps.Animation.BOUNCE
	});

	marker.setMap(map);
}

google.maps.event.addDomListener(window, 'load', initialize);



//********************** Sign Up Page *******************

